/*
package com.yoga.manager.uitl;

import AppException;

import java.util.ArrayList;
import java.util.List;

*/
/**
 * Created by chenjin on 2020/9/16.
 *//*

public class GenerateCodeUtil {

    private final static Object OBJ = new Object();

    private static List<Character> characters;

    static {
        characters = new ArrayList<>();
        for (char i = '4'; i <= '9'; i++) {
            characters.add(i);
        }

        for (char i = 'A'; i <= 'Z'; i++) {
            characters.add(i);
        }
    }

    public static String generateInvitationCode(TeamDao teamDao) throws AppException{
        // 8位随机邀请码生成逻辑 ,同一时刻仅有一个线程调用这个方法。避免产生相同的邀请码。
        synchronized (OBJ) {
            while (true) {
                StringBuilder sb = new StringBuilder();
                long timestamp = System.currentTimeMillis();
                for (int i = 0; i < 9; i++) {
                    sb.append(characters.get((int) ((timestamp >> (5 * i)) & 0x1f)
                            % characters.size()));
                }
                String invitationCode = sb.reverse().toString();
                if (teamDao.findByCode(invitationCode) == null) {
                    return invitationCode;
                } else {

                }
            }
        }
    }

    public static String generateBusinessCode(BusinessMemberDao businessMemberDao) throws AppException{
        // 8位随机邀请码生成逻辑 ,同一时刻仅有一个线程调用这个方法。避免产生相同的邀请码。
        synchronized (OBJ) {
            while (true) {
                StringBuilder sb = new StringBuilder();
                long timestamp = System.currentTimeMillis();
                for (int i = 0; i < 9; i++) {
                    sb.append(characters.get((int) ((timestamp >> (5 * i)) & 0x1f)
                            % characters.size()));
                }
                String invitationCode = sb.reverse().toString();
                if (businessMemberDao.findByBusinessCode(invitationCode) == null) {
                    return invitationCode;
                } else {

                }
            }
        }
    }



}
*/
